const redisClient = require('../config/redis')
async function redisMiddleware(req, res, next) {
    const token = req.headers.authorization
    if (token) {
        try{
        await redisClient.connect().catch(console.error)
        const result = await redisClient.sIsMember('logoutTokens', token)
        if(result){
            res.status(401).json({
                msg: 'token失效'
            })
        }
        await redisClient.quit()
    }
    catch(e){
        console.log('redis connect err,'+ e)
    }

  }
  next()
}
module.exports = redisMiddleware
